import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import { renderWithQiankun, qiankunWindow } from "vite-plugin-qiankun/es/helper";

let app = null;
const render = (props = {}) => {
  const { container, setGlobalState } = props;

//   if (getGlobalState) {
//     store.count = getGlobalState().count;
//   }
  app = createApp(App, { setGlobalState });
  app.use(router);
  app.mount(container ? container.querySelector("#vue3-app") : "#vue3-app");
};

const initQianKun = () => {
  renderWithQiankun({
    mount(props) {
      render(props);
    },
    bootstrap() {
      console.log("vue3 app bootstraped");
    },
    unmount() {
      app.unmount();
      app._container.innerHTML = "";
      app = null;
    },
  });
};

// 如果不是通过qiankun启动的，则单独渲染
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render();
// const app = createApp(App)

// app.use(createPinia())
// app.use(router)

// app.mount('#app')
